package com.waghost.bridalgown.controller;

import com.waghost.bridalgown.annotaion.Logging;
import com.waghost.bridalgown.entity.Result;
import com.waghost.bridalgown.entity.UserBgLike;
import com.waghost.bridalgown.entity.UserInfo;
import com.waghost.bridalgown.service.UserBgLikeService;
import com.waghost.bridalgown.utils.UserUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
// 用户收藏
@RestController
@CrossOrigin
@AllArgsConstructor
@RequestMapping("/ubl")
public class UserBgLikeController {

    private UserBgLikeService userBgLikeService;
    private UserUtils utils;

    @GetMapping("/list")
    public Result list() {
        return userBgLikeService.list();
    }

    @GetMapping("/get")
    public Result get(HttpServletRequest request) {
        UserInfo user = utils.getUser(request);
        return userBgLikeService.getId(user.getId());
    }

    @PostMapping("/add")
    @Logging(type = 1, uuid = 6)
    public Result addUser(@RequestBody UserBgLike bgLike, HttpServletRequest request) {
        bgLike.setUserId(utils.getUser(request).getId());
        return userBgLikeService.add(bgLike);
    }

    @PostMapping("/edit")
    @Logging(type = 3, uuid = 6)
    public Result editUser(@RequestBody UserBgLike bgLike) {
        return userBgLikeService.update(bgLike);
    }

    @PostMapping("/del/{id}")
    @Logging(type = 2, uuid = 6)
    public Result delUser(@PathVariable("id") Integer id) {
        return userBgLikeService.delete(id);
    }


}
